from django.db import models
from django.utils import timezone

# Create your models here.

# version_9 新加评论功能的相关数据库模型

class Comment(models.Model):
    name = models.CharField('名字',max_length=50)
    email = models.EmailField('邮箱')           #EmailField是个新的数据类型
    url = models.URLField('网址',blank=True)
    text = models.TextField('内容')
    created_time = models.DateTimeField('创建时间',default=timezone.now)
    post = models.ForeignKey('polls.Post',verbose_name='文章',on_delete=models.CASCADE)


    class Meta:
        verbose_name = '评论'
        verbose_name_plural = verbose_name
        # version_11 添加排序属性
        ordering = ['-created_time']


    def __str__(self):
        return '{}:{}'.format(self.name,self.text[:20])   
